from typing import ClassVar
from pandas import Index
from sklearn.feature_selection import RFE
from selector._base_selector import _BaseSelector


class Wrapper(_BaseSelector):
    """
    Wrapper method of feature selection, subclass of _BaseFeatureSelector.
    Parameters:
        same with father class
    """

    def __init__(self, x, y, n_selected_features):
        super(Wrapper, self).__init__(x, y, n_selected_features)

    def select_features(self, estimator: ClassVar) -> Index:
        """
        Parameters:
            estimator: ClassVar,
                {Ridge(), Lasso(), RandomForestRegressor(), AdaBoostRegressor(), GradientBoostingRegressor()}
        Return:
            Index, names of sorted selected features
        """
        selector = RFE(estimator=estimator, n_features_to_select=self.n_selected_features)
        selector.fit(self.x, self.y)
        return super(Wrapper, self).sort_features(selector.ranking_)

